package java19_1_8.interface_test;

import java.io.Serializable;

/**
 * @author yuisama
 * @date 2022/01/08 15:07
 **/
class A implements Cloneable, Serializable {
    int num;

    @Override
    protected A clone() throws CloneNotSupportedException {
        return (A) super.clone();
    }
}
public class B implements Cloneable{
    A a = new A();
    @Override
    protected B clone() throws CloneNotSupportedException {
        B newB = (B) super.clone();
        newB.a = a.clone();
        return newB;
    }

    public static void main(String[] args) throws CloneNotSupportedException {

        B b1 = new B();
        B b2 = b1.clone();
        // false
        System.out.println(b1 == b2);
        System.out.println(b2.a.num);
        b1.a.num = 100;
        System.out.println(b2.a.num);
    }
}